"""测试文件"""

import datetime
import re
import uuid
import json

# print(re.match("https://yyk.99.com.cn/[a-z]*/\d+/","https://yyk.99.com.cn/xiayi/81354/baocuo.html"))
# print(str(uuid.uuid1()).replace("-",""))
# item = {}
# province = item["c_province"] = "湖北省"
# city = item["c_city"] = "神农架林区"
# area = item["c_area"] = "None"
# with open("E:\PycharmProjects\hospitalSpider\province.json", "r",encoding="UTF-8") as json_object:
#     list = json.load(json_object)
#     flag = False
#     for i in list:
#         if province == i["label"]:
#             item["c_province"] = i["value"]
#             for j in i["children"]:
#                 if "children" in j.keys():
#                         for k in j["children"]:
#                             if area in k["label"] or city in k["label"]:
#                                 item["c_area"] = k["value"]
#                                 item["c_city"] = j["value"]
#                                 flag = True
#                                 break
#                 if flag:
#                     break
#         if flag:
#             break
# print(item)


# item ={}
# dd = datetime.date(2021,1,1)
# print(dd)
# item["date"] = dd
# item["name"] = "路飞"
# print(item)

#
# level = "三级甲等"
# print( level[0:2])
# print(level[2:4])

# a = "你好"
b = "abcde"
# print(a in b)

# print(str(b))
#
# print(b[0:len(b)-1])


import xlwt
import pandas as pd


def export_excel(export):
    # 将字典列表转换为DataFrame
    pf = pd.DataFrame(list(export))
    # 指定字段顺序
    order = ['road_name', 'bus_plate', 'timeline', 'road_type', 'site']
    pf = pf[order]
    # 将列名替换为中文
    columns_map = {
        'road_name': '路线',
        'bus_plate': '车牌',
        'timeline': '时间',
        'road_type': '方向',
        'site': '站点'
    }
    pf.rename(columns=columns_map, inplace=True)
    # 指定生成的Excel表格名称
    file_path = pd.ExcelWriter('test.xlsx')
    # 替换空单元格
    pf.fillna(' ', inplace=True)
    # 输出
    pf.to_excel(file_path, encoding='utf-8', index=False)
    # 保存表格
    file_path.save()


if __name__ == '__main__':
    # 将分析完成的列表导出为excel表格
    tables = [
        {"road_name": "1", "bus_plate": "2", "timeline": "3", "road_type": "4", "site": "5"},
        {"road_name": "2", "bus_plate": "2", "timeline": "3", "road_type": "4", "site": "5"},
        {"road_name": "3", "bus_plate": "2", "timeline": "3", "road_type": "4", "site": "5"},
        {"road_name": "4", "bus_plate": "2", "timeline": "3", "road_type": "4", "site": "5"},
        {"road_name": "5", "bus_plate": "2", "timeline": "3", "road_type": "4", "site": "5"},
        {"road_name": "6", "bus_plate": "2", "timeline": "3", "road_type": "4", "site": "5"},
    ]
    export_excel(tables)
